document.addEventListener("DOMContentLoaded", function () {
    var input = document.getElementById("inputreadId");
    $.ajax({
        url: "/reader/getReadId",
        async : false,
        type: "POST",
        success: function (readId) {
            input.value = readId;
        },
        error: function (error) {
            console.log("请求出错：", error);
        }
    });
});

$("#btn-add").click(function (event) {
    event.preventDefault();
    var readId = $("#inputreadId").val();
    var jsId = $("#inputjsId").val();
    $.ajax({
        url: "/reader/addReaderCard",
        type: "POST",
        data: {
            readId: readId,
            jsId: jsId
        },
        success: function (res) {
            if(res === 'success'){
                alert("办理成功");
                window.location.href = "./readerCardInfoHtml";
            }else if(res === 'exist'){
                alert("借阅证已办理，无需重复办理");
                window.location.href = "./readerCardInfoHtml";
            }else{
                alert("添加失败,请联系管理员");
            }
        },
        error: function () {
            alert("请求失败");
        }
    })
})